/// 新闻分页 request
class NewsPageListRequest {
  String? categoryCode;
  String? channelCode;
  String? tag;
  String? keyword;

  NewsPageListRequest({
    this.categoryCode,
    this.channelCode,
    this.tag,
    this.keyword,
  });

  Map<String, dynamic> toJson() => {
    "categoryCode": categoryCode,
    "channelCode": channelCode,
    "tag": tag,
    "keyword": keyword,
  };
}

/// 新闻分页 response
class NewsPageListResponse {
  int? counts;
  int? pagesize;
  int? pages;
  int? page;
  List<NewsItem>? items;

  NewsPageListResponse({
    this.counts,
    this.pagesize,
    this.pages,
    this.page,
    this.items,
  });

  factory NewsPageListResponse.fromJson(Map<String, dynamic> json) =>
      NewsPageListResponse(
        counts: json["counts"],
        pagesize: json["pagesize"],
        pages: json["pages"],
        page: json["page"],
        items:
        List<NewsItem>.from(json["items"].map((x) => NewsItem.fromJson(x))),
      );

  Map<String, dynamic> toJson() => {
    "counts": counts,
    "pagesize": pagesize,
    "pages": pages,
    "page": page,
    "items": List<dynamic>.from(items!.map((x) => x.toJson())),
  };
}

class NewsItem {
  String? id;
  String? title;
  String? category;
  String? thumbnail;
  String? author;
  DateTime? addtime;
  String? url;

  NewsItem({
    this.id,
    this.title,
    this.category,
    this.thumbnail,
    this.author,
    this.addtime,
    this.url,
  });

  factory NewsItem.fromJson(Map<String, dynamic> json) => NewsItem(
    id: json["id"],
    title: json["title"],
    category: json["category"],
    thumbnail: json["thumbnail"],
    author: json["author"],
    addtime: DateTime.parse(json["addtime"]),
    url: json["url"],
  );

  Map<String, dynamic> toJson() => {
    "id": id,
    "title": title,
    "category": category,
    "thumbnail": thumbnail,
    "author": author,
    "addtime": addtime?.toIso8601String(),
    "url": url,
  };
}

/// 新闻推荐 request
class NewsRecommendRequest {
  String? categoryCode;
  String? channelCode;
  String? tag;
  String? keyword;

  NewsRecommendRequest({
    this.categoryCode,
    this.channelCode,
    this.tag,
    this.keyword,
  });

  Map<String, dynamic> toJson() => {
    "categoryCode": categoryCode,
    "channelCode": channelCode,
    "tag": tag,
    "keyword": keyword,
  };
}

/// 新闻推荐 response
class NewsRecommendResponse {
  String? thumbnail;
  String? title;
  String? category;
  DateTime? addtime;
  String? author;
  String? url;
  String? id;

  NewsRecommendResponse({
    this.thumbnail,
    this.title,
    this.category,
    this.addtime,
    this.author,
    this.url,
    this.id,
  });

  factory NewsRecommendResponse.fromJson(Map<String, dynamic> json) =>
      NewsRecommendResponse(
        thumbnail: json["thumbnail"],
        title: json["title"],
        category: json["category"],
        addtime: DateTime.parse(json["addtime"]),
        author: json["author"],
        url: json["url"],
        id: json["id"],
      );

  Map<String, dynamic> toJson() => {
    "thumbnail": thumbnail,
    "title": title,
    "category": category,
    "addtime": addtime?.toIso8601String(),
    "author": author,
    "url": url,
    "id": id,
  };
}
